package fr.toto.exceptions;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.BindException;
import java.net.URISyntaxException;

import javax.swing.JOptionPane;

import fr.toto.constantes.Constantes;

public class ProcessException implements Constantes {

	public ProcessException(Exception e) {
		
		if(settings.isDebug())
			e.printStackTrace();

		if ((e instanceof UnsupportedEncodingException)
				|| (e instanceof FileNotFoundException)
				|| (e instanceof URISyntaxException)
				|| (e instanceof ClassNotFoundException)
				|| (e instanceof IOException)) {

			// TODO traiter les différentes exceptions
		}
		if (e instanceof BindException) {
			String m = String.format(MESSAGES.getString("BindException"), e.getMessage());
			JOptionPane.showMessageDialog(null, m.toString());
		} else {

			String m = e.toString();
			if (e.getStackTrace() != null)
				for (StackTraceElement ste : e.getStackTrace()) {
					if (ste.getFileName() != null)
						m += "\n\t " + ste.toString();
				}
			JOptionPane.showMessageDialog(null, m.toString());
		}

	}

}
